package test;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisSentinelPool;

public class ClusterDemo {

	public static void main(String[] args) throws InterruptedException {
		// Sentinel集群地址
		String servers = "10.16.34.125:6406,10.16.34.15:6382,10.16.34.16:6382";
		Set<String> clusters = new HashSet<String>();
		if (servers != null){
		    clusters.addAll(Arrays.asList(servers.split(",")));
		}
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
		poolConfig.setMaxTotal(20);
		poolConfig.setMaxIdle(10);
		poolConfig.setMinIdle(10);
		poolConfig.setMaxWaitMillis(2000);
		poolConfig.setTestOnBorrow(true);
		poolConfig.setTestOnReturn(true);
		poolConfig.setTestWhileIdle(true);
		poolConfig.setTimeBetweenEvictionRunsMillis(1000);
        JedisSentinelPool jedisSentinelPool = new JedisSentinelPool("sentinel-10.16.34.15-6381", clusters, poolConfig, 100, 500, null, 4);
        Jedis jedis = jedisSentinelPool.getResource();
        System.out.println(jedis.set("name".getBytes(), "test".getBytes()));
        System.out.println(new String(jedis.get("name".getBytes())));
        System.out.println(jedis.del("name".getBytes()));
        jedis.close();
        Thread.sleep(1000000);
	}

}
